package com.unism.data.collect;

import java.io.IOException;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.junit.Assert;

import com.unism.util.ResponseByJson;


public class HttpClient {
	private final String str = "//http://120.27.55.192:8080/data/collectdata/";

	public HttpClient() {
		// TODO Auto-generated constructor stub
	}

	public void doGet(String method, String para) throws JsonGenerationException, JsonMappingException, IOException {

		ClientConfig clientConfig = new ClientConfig();
		clientConfig.register(JacksonFeature.class);

		Client client = ClientBuilder.newClient(clientConfig);
		String url = str + method + "?" + para;
		WebTarget webTarget = client.target(url);

		Builder request = webTarget.request(MediaType.APPLICATION_JSON);

		Response response = request.get();
		Assert.assertTrue(response.getStatus() == 200);

		ResponseByJson vo = response.readEntity(ResponseByJson.class);

		ObjectMapper mapper = new ObjectMapper();
		System.out.println("########################################################\r\nURL：" + url + "\r\n"
				+ mapper.writerWithDefaultPrettyPrinter().writeValueAsString(vo));

	}

	public static void main(String[] args){
		
	}
}
